/*
 *  AudioStreamer.cpp.h
 *  SoundController0002
 *
 *  Created by jiro on 10/07/03.
 *  Copyright 2010 jiro music. All rights reserved.
 *
 */

#pragma once

#include "AudioChannel.h"
#include <vector>
#include "AudioChannelStream.h"

namespace sc
{
	template< class AudioData >
	class AudioStream
	{
	private:

		std::vector< AudioChannelStream< AudioData > > audioChannelStreams;

	public:
	
		AudioStream( const std::vector< AudioChannel< AudioData > >& channels )
		{
			size_t count = channels.size();
			audioChannelStreams.resize( count );
			for ( size_t i = 0; i < count; i++ )
			{
				audioChannelStreams[ i ] = channels[ i ];
			}
		}

		void StartStreaming( double time )
		{
			size_t count = audioChannelStreams.size();
			for ( size_t i = 0; i < count; i++ )
			{
				audioChannelStreams[ i ].StartStreaming( time );
			}
		}

		float Stream()
		{
			AudioData audioData = 0.0;
			size_t count = audioChannelStreams.size();
			for ( size_t i = 0; i < count; i++ ) 
			{
				audioData += audioChannelStreams[ i ].Stream();
			}
			return audioData;
		}
		
		bool IsStreamingEnd() const
		{
			size_t count = audioChannelStreams.size();
			for ( size_t i = 0; i < count; i++ ) 
			{
				if ( ! audioChannelStreams[ i ].IsStreamingEnd() )
				{
					return false;
				}
			}
			return true;
		}

	};
}
